﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SES.CMS.DO;
using SES.CMS.BL;

namespace SES.CMS
{
    public partial class Article : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["ID"] != null)
            {
                if (Session["lang"] != null)
                {
                    string s = Request.QueryString["ID"].ToString();
                    int id = int.Parse(s);
                    cmsArticleDO objCat = new cmsArticleDO();
                    objCat.ArticleID = id;
                    objCat = new cmsArticleBL().Select(objCat);
                    imgContent.ImageUrl = "/Media/" + objCat.ImageUrl;
                    hplImg.NavigateUrl = "/Media/" + objCat.ImageUrl;
                    if (Session["lang"].ToString() == "VN")
                    {
                        Page.Title = objCat.Title + " - KMA";
                        lblInfo.Text = objCat.ArticleDetail;
                        lblDes.Text = objCat.Description;
                        lblTitle.Text = objCat.Title;
                        hplImg.Attributes.Add("Title", objCat.Title);
                        imgContent.Attributes.Add("AlternateText", objCat.Title);
                    }
                    else
                    {
                        Page.Title = objCat.eTitle + " - KMA";
                        lblInfo.Text = objCat.eArticleDetail;
                        lblTitle.Text = objCat.eTitle;
                        lblDes.Text = objCat.eDescription;
                        hplImg.Attributes.Add("Title", objCat.eTitle);
                        imgContent.Attributes.Add("AlternateText", objCat.eTitle);
                    }
                    DataTable dt = new DataTable();
                    dt = new DataView(new cmsArticleBL().SelectByCategoryID(objCat.CategoryID, 10), "ArticleID<>" + objCat.ArticleID.ToString() + "", "ArticleID DESC", DataViewRowState.CurrentRows).ToTable();
                    if (dt.Rows.Count > 0)
                    {
                        rpt.Visible = true;
                        rpt.DataSource = dt;
                        rpt.DataBind();
                    }
                    else
                    {
                        rpt.Visible = false;
                    }
                }
            }
        }
        public string Change_AV(string ip_str_change)
        {
            return Ultility.Change_AV(ip_str_change);
        }
        public string CheckDate(string sDate)
        {
            if (sDate != "")
            {
                //kiem tra ngay thang neu nho hon ngay hien tai (chu y parse sang datetime) 
                DateTime startDate = Convert.ToDateTime(sDate);
                DateTime now = DateTime.Now;
                TimeSpan elapsed = now.Subtract(startDate);
                double daysAgo = elapsed.TotalDays;
                if (daysAgo < 30)
                {
                    //return "<span class=\"red\">" + sDate; 
                    //return "<asp:Image ID=\"imgNew\" ImageUrl=\"~/images/New_icons_07.gif\" runat=\"server\" AlternateText=\"New\" />";
                    return "<img src=\"/images/New_icons_07.gif\" AlternateText=\"New\" />";
                }
                else
                {
                    return " ";
                }
            }
            else
                return "";
        }
    }
}
